package com.link2room.rodimus.service.impl;

import com.link2room.common.dto.result.base.MemberSessionDto;
import com.link2room.common.dto.threadlocal.ApiThreadLocal;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.exception.SysException;
import com.link2room.common.mns.MNSUtil;
import com.link2room.common.util.JacksonUtil;
import com.link2room.rodimus.dto.result.base.DrawPrizeBaseDto;
import com.link2room.rodimus.entity.DrawPrizeBaseEntity;
import com.link2room.rodimus.entity.MemberBase;
import com.link2room.rodimus.service.IAfterDrawHandleService;
import com.link2room.trailbreaker.dto.param.WxRedpackSendParamDto;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.link2room.trailbreaker.constant.TrailbreakerMnsConstant.QUEUE_RED_PACK;

/**
 * Created by LN on 2017/10/24
 */
@Component("redpackAfterDrawHandleService")
public class AfterDrawHandleRedpackServiceImpl extends AbstractArfterDrawHandlerServiceImpl implements IAfterDrawHandleService {
    @Resource
    private MNSUtil mnsUtil;

    @Override
    void doAfterDraw(DrawPrizeBaseDto drawPrizeBaseDto) throws Exception {
        MemberSessionDto memberSession = ApiThreadLocal.getMemberSessionThreadLocal();
        String rule = drawPrizeBaseDto.getRule();
        WxRedpackSendParamDto sendRedParam = JacksonUtil.jsonToBean(rule,WxRedpackSendParamDto.class);
        sendRedParam.setLhotelGroupCode(drawPrizeBaseDto.getLhotelGroupCode());
        sendRedParam.setBillno(drawPrizeBaseDto.getPrizeNo());
        sendRedParam.setReOpenid(memberSession.getOpenid());
        sendRedParam.setTotalAmount(drawPrizeBaseDto.getValue());
        mnsUtil.putMessageToQueue(QUEUE_RED_PACK, JacksonUtil.beanToJson(sendRedParam));
    }

    @Override
    void redoAfterDraw(MemberBase memberBase, String openid, DrawPrizeBaseEntity prizeBase) throws Exception {
        throw new SysException(BaseSysExceptionEnum.BASE_FUCATION_OPTION,"方法没有实现");
    }

}
